<template>
  <div class="login-container">
    <el-card header="请登录" class="login-card">
      <el-form>
        <el-form-item label="用户名">
          <el-input v-model="model.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="model.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Login",
  data() {
    return {
      model: {},
    };
  },
  methods: {
    login() {
      this.$http
        .post("login", this.model)
        .then((res) => {
          localStorage.token = res.data;
          this.$router.push("/");
          this.$message({
            type: "success",
            message: "登录成功",
          });
        })
        .catch((err) => {
          console.log("err", err.response.data);
        });
    },
  },
};
</script>

<style scoped>
.login-card {
  margin: 10rem auto;
  width: 25rem;
}
</style>
